/*
 * Created on Mar 1, 2004
 *
 * 03/29/2004: this class is ready to go
 * 
 */
package rcscene;

import java.io.Serializable;

/** Holds data about an action taken by the player
 * @author kevlam
 *
 */
public class Action implements Serializable
{


	private static final long serialVersionUID = 1L;
	
	public static final int ACTION_NONE = 0;
	public static final int ACTION_DASH = 1;
	public static final int ACTION_KICK = 2;
	public static final int ACTION_TURNNECK = 3;
	public static final int ACTION_TURN = 4;
	public static final int ACTION_CATCH = 5;
	public static final int ACTION_MOVE = 6;
	
	//statistic indicators
	public static final float DASH_SD = 150;
	public static final float TURN_SD = 20;
	public static final float KICK_SD = 15;
	
	public static final String[] actions = { "none", "dash", "kick", "turn neck", "turn", "catch", "move"};
	
	private int action;
	private double action_power;
	private double action_direction;
	private double action_x;
	private double action_y;

	/** Default constructor. Sets the actions to "none" and power, direction
	 * x and y to 0.
	 * 
	 */
	public Action()
	{
		action = ACTION_NONE;
		action_direction = 0;
		action_power = 0;
		action_x = 0;
		action_y = 0;
	}

	/** A copy constructor. The new Action will contain the action number,
	 * direction, power, X and Y of the supplied action.
	 * 
	 * @param other The action to copy
	 */
	public Action(Action other)
	{
		action = other.getAction();
		action_direction = other.getActionDirection();
		action_power = other.getActionPower();
		action_x = other.getActionX();
		action_y = other.getActionY();
	}

	
	/** Constructor with a supplied action type
	 * 
	 * @param act Action type
	 */
	public Action(int act)
	{
		testAction(act);
		action = act;
		action_direction = 0;
		action_power = 0;
		action_x = 0;
		action_y = 0;
	}

	
	/** Return the action number
	 * @return action number
	 */
	public int getAction()
	{
		return action;
	}
	
	/** Set the action number
	 * @param i The action number
	 */
	public void setAction(int i)
	{
		testAction(i);
		action = i;
	}

	/** Return the action direction
	 * @return action direction
	 */
	public double getActionDirection()
	{
		return action_direction;
	}

	/** Set the action direction
	 * @param f the action direction
	 */
	public void setActionDirection(double f)
	{
		action_direction = f;
	}
	
	/** Return the action power
	 * @return the action power
	 */
	public double getActionPower()
	{
		return action_power;
	}

	/** Set the action power
	 * @param f the action power
	 */
	public void setActionPower(double f)
	{
		action_power = f;
	}
	
	/** Get the action X value
	 * @return
	 */
	public double getActionX()
	{
		return action_x;
	}

	/** Set the action X value
	 * @param f
	 */
	public void setActionX(double f)
	{
		action_x = f;
	}
	
	/** Get the action Y value
	 * @return
	 */
	public double getActionY()
	{
		return action_y;
	}


	/** Set the action Y value
	 * @param f
	 */
	public void setActionY(double f)
	{
		action_y = f;
	}
	
	/** Test if two actions are equal
	 * 
	 * @param other The action to compare with
	 * @return true if they are equal, false otherwise
	 */
	public boolean equals(Action other)
	{
		if ( (action == other.getAction()) && (action_direction == other.getActionDirection())
				&& (action_power == other.getActionPower()) && (action_x == other.getActionX())
				&& (action_y == other.getActionY()) )
		{
			return true;
		}
		else 
		{
			return false;
		}
	}
	
	/** Textual representation of the action
	 * 
	 */
	public String toString()
	{
		return actions[action] + " power "+this.getActionPower()+ " dir : "+getActionDirection();
	}

	/** This method is used to test if the supplied action number is
	 * within the allowable range.
	 * 
	 * @param act The action number
	 */
	private void testAction(int act){
		if(act >= actions.length || act < 0 ){
			throw new IllegalArgumentException("Invalid action type.");
		}
	}


	
}
